import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/// 通用的列表项组件
class ListItemRow extends StatelessWidget {
  final String title;
  final bool editable;
  final String? value;
  final TextEditingController? controller;
  final String hintText;
  final VoidCallback? onTap; // 👈 点击文字时回调

  const ListItemRow({
    super.key,
    required this.title,
    this.editable = false,
    this.value,
    this.controller,
    this.hintText = "请输入",
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: editable ? null : onTap, // 只有文字模式下才允许点击
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
        decoration: const BoxDecoration(
          border: Border(
            bottom: BorderSide(color: CupertinoColors.systemGrey4, width: 0.5),
          ),
        ),
        child: Row(
          children: [
            /// 左侧标题
            Text(
              title,
              style: const TextStyle(
                fontSize: 16,
                color: CupertinoColors.label,
              ),
            ),
            const Spacer(),

            /// 右侧内容
            if (editable)
              SizedBox(
                width: 150,
                child: CupertinoTextField(
                  controller: controller,
                  placeholder: hintText,
                  padding: const EdgeInsets.symmetric(
                    horizontal: 8,
                    vertical: 6,
                  ),
                ),
              )
            else
              Text(
                value ?? hintText,
                style: TextStyle(
                  fontSize: 16,
                  color: value == null
                      ? CupertinoColors.systemGrey2
                      : CupertinoColors.label,
                ),
              ),
          ],
        ),
      ),
    );
  }
}
